import { NgModule, LOCALE_ID, APP_INITIALIZER } from '@angular/core';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { DelonModule } from './delon.module';
import { SharedModule } from './shared/shared.module';
import { AppComponent } from './app.component';
import { RoutesModule } from './routes/routes.module';
import { LayoutModule } from './layout/layout.module';
import { StartupService } from '@core/startup/startup.service';
import { LocalStorage } from '@core/local.storage';
// angular i18n
import { DefaultInterceptor } from './core/net/default.interceptor';
import { registerLocaleData } from '@angular/common';
import zh from '@angular/common/locales/zh';
registerLocaleData(zh);

export function StartupServiceFactory(startupService: StartupService) {
  return () => startupService.load();
}

@NgModule({
  imports: [// 导入其他模块，表示该模块依赖其他模块的组件
    BrowserModule,
    BrowserAnimationsModule,
    HttpClientModule,
    DelonModule.forRoot(),
    SharedModule,
    LayoutModule,
    RoutesModule
  ],
  declarations: [// 声明哪些组件属于该模块
    AppComponent
  ],
  providers: [// 申明该模块使用哪些service
    {
      provide: LOCALE_ID,
      useValue: 'zh-Hans'
    },
    StartupService,
    LocalStorage,
    {
      provide: APP_INITIALIZER,
      useFactory: StartupServiceFactory,
      deps: [StartupService],
      multi: true
    },
    {
      provide: HTTP_INTERCEPTORS,
      useClass: DefaultInterceptor,
      multi: true
    }
  ],
  bootstrap: [// 模块的启动组件
    AppComponent
  ]
})
export class AppModule {}
